/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     ListNode *next;
 *     ListNode() : val(0), next(nullptr) {}
 *     ListNode(int x) : val(x), next(nullptr) {}
 *     ListNode(int x, ListNode *next) : val(x), next(next) {}
 * };
 */
class Solution {
public:
    bool isPalindrome(ListNode* head) {
        int cnt = 0;
        vector<int>ans;
        while (head) {
            ans.push_back(head->val);
            head = head->next;
            cnt++;
        }
        for (int i = 0; i < cnt / 2; i++) {
            if (ans[i] != ans[cnt - i - 1])return 0;
        }
        return 1;
    }
};